<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use User\Api\UserApi;

/** 
 * 后台用户控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class SupplierController extends AdminController { 
    /**
     * 供应商
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     */
    /*列表页 20180206  by  zhanghao*/ 
    public function lists(){ 
        $map["id"]   = (int)$_POST['id']; 
        $map["name"] = $_POST['name'];
        $map["tel"]  = $_POST['tel']; 
        if(IS_POST){      
            $res = M("supplier")->where('id='. $map["id"])->save($map);  
        }
        unset($map);
        $map['is_delete'] = 0;  
        $info = M('supplier')->where($map)->select();  
        $this->assign('info',$info); 
        $this->display();  
    }
    /*新增 20180206  by  zhanghao*/
    public function add(){  
         $data['name'] = $_POST['name']; 
         $data['tel']  = $_POST['tel'];     
         $data['create_time'] = time();  
         $res = M("supplier")->add($data);   
        if($res == true){
            $this->success('新增成功');
        }
        else{
            $this->error('新增失败');
        }   
    } 
    /*编辑 20180206  by  zhanghao*/
    public function edit()
    {
        $map['id'] = $_POST['ID'];  
        $map['is_delete'] = 0; 
        $list = M("supplier")->where($map)->select(); 
        $this->ajaxReturn($list); 
    }
    /*删除 20180206  by  zhanghao*/
    public function del()
    { 
        $id = I('id');  
        $data['is_delete']=1; 
        $re = M('supplier')->where(array('id'=>$id))->save($data); 
        if($re == true){
            $this->success('删除成功');
        }
        else{
            $this->error('删除失败');
        } 
    }
    /*禁用 20180206  by  zhanghao*/
    public function forbidden()
    {  
        $id = I('id');  
        $data['status']=0; 
        $re = M('supplier')->where(array('id'=>$id))->save($data);
        
        if($re == true){
            $this->success('禁用成功');
        }
        else{
            $this->error('禁用失败');
        } 
    } 
    /*启用 20180206  by  zhanghao*/
    public function start()
    {  
        $id = I('id');  
        $data['status']=1; 
        $re = M('supplier')->where(array('id'=>$id))->save($data); 
        if($re == true){
            $this->success('启用成功');
        }
        else{
            $this->error('启用失败');
        } 
    }  
 
}
